{extend name="public/base"}
{block name='main'}
<form class="layui-form layui-form-pane" action="" style="padding:20px;">
    <input type="hidden" name="start_time" value="2018-05-29" />
    <input type="hidden" name="end_time" value="2030-05-29" />
    <div class="layui-form-item">
        <label class="layui-form-label">{$info.id|default=''}广告名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" placeholder="请输入" class="layui-input" value="{$info.name|default=''}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">广告链接</label>
        <div class="layui-input-block">
            <input type="text" name="url" id="url" placeholder="请输入" class="layui-input" value="{$info.url|default=''}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">广告位</label>
        <div class="layui-input-block">
            {if $id==0}
            <select name="board_id" id="board_id">
                {volist name="adboards" id="val" }
                    <option value="{$val.id}" allowtype="{$val.allow_type}">{$val.name}（{$val.width}*{$val.height}）</option>
                {/volist}
            </select>
            {else/}
            <input type="text" class="layui-input" value=" {$board_info.name|default=''} ({$board_info.width|default=''}*{$board_info.height|default=''}) - 禁止编辑" disabled="">
            {/if}
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">广告类型</label>
        <div class="layui-input-block">
            <select name="type" id="type" lay-filter="leixing">
                {volist name="ad_type_arr" id="val" }
                <option value="{$key}"  {eq name="info.type|default=''" value="$key"}selected="selected"{/eq}>{$val}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item" id="ad_image" style="display:none;">
        <label class="layui-form-label">广告图片</label>
        <div class="layui-input-block">
            <button type="button" name="img1" class="layui-btn layui-btn-primary" id="upimg"><i class="layui-icon"></i>只允许图片文件</button>
            <div class="layui-form-mid " style="width: 100%">
                <img src={eq name="$info.content|default=''" value=''}{else/}{:upload_url($info['content'], 'ad')}{/eq}  height="36" id="imgval" >
            </div>
        </div>
    </div>

    <div class="layui-form-item" id="ad_code" style="display:none;">
        <label class="layui-form-label">广告代码</label>
        <div class="layui-input-block">
            <textarea name="code" id="intro" class="layui-textarea">{$info.content|default=''}</textarea>
        </div>
    </div>
    <div class="layui-form-item" id="ad_text" style="display:none;">
        <label class="layui-form-label">广告文字</label>
        <div class="layui-input-block">
            <textarea name="text" id="text" class="layui-textarea">{$info.content|default=''}</textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class=""></label>
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="content_edit">提交保存</button>
        </div>
    </div>

    <input type="hidden" name="img" id="J_img" value="{$info.content|default=''}">
    <input type="hidden" name="id" id="id" value="{$info.id|default=''}" />
</form>
<script type="text/javascript" src="__PUBLIC__/admin/layui/layui.js"></script>
<script>
    layui.use(['layer','jquery','form','upload'], function () {
        // 操作对象
        var layer = layui.layer,$ = layui.jquery,form = layui.form, upload = layui.upload;


        //上传图片
        upload.render({
            elem: '#upimg'
            ,url: "{:url('ad/ajax_upload_img')}"
            ,field:'file'
            ,acceptMime: 'image/*'
            ,done: function(res, index, upload){
                if (res.status == 1) {
                    layer.msg('上传成功',{time:1800});
                    $('#J_img').val(res.info);
                    $('#imgval').show().attr('src',res.img_url);
                }else {
                    layer.msg('上传失败',{time:1800});
                }
            }
        });

        //当前类型
        $(function(){
            var style = "{$info.type|default='image'}";
            $('#ad_'+ style).show();
        });

        //选择类型
        form.on('select(leixing)', function(data){
            if (data.value == 'code') {
                $('#ad_code').show();
                $('#ad_text').hide();
                $('#ad_image').hide();
            }
            if (data.value == 'text') {
                $('#ad_code').hide();
                $('#ad_text').show();
                $('#ad_image').hide();
            }
            if (data.value == 'image') {
                $('#ad_code').hide();
                $('#ad_text').hide();
                $('#ad_image').show();
            }

        });
        //参数：layui、名称、更新的formid、更新的url：module/method、更新后跳转的url（为空则不跳转）、编辑器id、标签id（为空则不获取）
        Oper.initUpdate(layui, '广告', 'content_edit', 'ad/add');
    });
</script>
{/block}